<%--
  Created by IntelliJ IDEA.
  User: 诸葛龙辰
  Date: 2023/3/3
  Time: 20:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>更改</title>
    <script type="text/javascript" src="/js/jquery-3.4.1.min.js"></script>
</head>
<body>
<h2 align="center">更改</h2>
<div style="color: red" id="error"></div>
<form id="deptFrm">
    <table border="1" width="600px" align="center">
        <tr style="background-color: red">
            <td>员工编号：</td>
            <td><input  readonly="readonly"  type="hidden" name="embId" id="embId"></td>
        </tr>
        <tr style="background-color: red">
            <td>员工名称：</td>
            <td><input type="text" name="empName" id="empName"></td>
        </tr>
        <tr>
        <td>年：</td>
        <td><input type="text" name="year" id="year"></td>
        </tr>
        <tr>
            <td>月：</td>
            <td><input type="text" name="month" id="month"></td>
        </tr>
        <tr>
            <td>工资：</td>
            <td><input type="text" name="salary" id="salary"></td>
        </tr>
        <tr>
            <td>地址：</td>
            <td><input type="text" name="loc" id="loc"></td>
        </tr>
        <tr>
            <td colspan="2" align="center"><input type="button" id="btn" value="更新"></td>
        </tr>
    </table>
</form>
<script>
    let embId = ${param.embId};
    $(function (){
        $.ajax({
            url:"/EmpServlet/queryById1",
            type:"get",
            data:{embId:embId},
            contentType:"json",
            success:function (data){
                $("#embId").val(data.embId);
                $("#empName").val(data.empName);
                $("#year").val(data.year);
                $("#month").val(data.month);
                $("#salary").val(data.salary);
                $("#loc").val(data.loc);
            },
            error:function (data){

            }
        });
        $("#btn").click(function () {
            var dept =$("#deptFrm").serialize();
            $.ajax({
                url:"/EmpServlet/update1",
                type:"get",
                //dataType:"json",
                data:dept,
                contentType:"json",
                success:function (data) {
                    if(data>0){
                        location.href="/emp/list1.jsp";
                    }else {
                        $("#error").html("添加失败！");
                    }
                },
                error:function (data) {
                }
            });
        })
    })
</script>
</body>
</html>
